package com.example.service.impl;

import com.example.dao.UserDao;
import com.example.entity.User;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

   /* @Override
    public User getUserByUsername(String username) {
        return userDao.findByUsername(username);
    }*/

    @Override
    public User getUserByUserNameAndPassword(String username, String password) {
        return userDao.findByUserNameAndPassword(username, password);
    }

    @Override
    public int addUser(String username, String password, String email, String phone, int role) {
        return userDao.addUserDao(username,password,email,phone,role);
    }

    @Override
    public Integer getUserRole(int user_id) {
        return userDao.getUserRole(user_id);
    }
    @Override
    public List<User> userList() {
        return userDao.userListDao();
    }

    @Override
    public boolean deleteUser(Integer user_id) {
        return userDao.deleteUser(user_id) > 0;
    }

    @Override
    public boolean addUser(User user) {
        return userDao.insert(user) > 0;
    }

    @Override
    public boolean updateUser(User user) {
        return userDao.updateUser(user);
    }

    @Override
    public User getUserById(Integer user_id) {
        return userDao.getUserById(user_id);
    }
    @Override
    public User getUserById(int userId) {
        return userDao.getUserById(userId);
    }

    @Override
    public boolean updateUserProfile(Integer userId, String email, String phone) {
        User user = userDao.getUserById(userId);
        if (user == null) {
            return false;
        }
        user.setEmail(email);
        user.setPhone(phone);
        return userDao.updateUser(user);
    }

}
